#!/bin/bash

cd /var/log
mkdir -p cmd_history
chmod 777 cmd_history

echo "
export HISTTIMEFORMAT=\"%F %T \`who am i | awk 'BEGIN{OFS=\" \";}{print \$1,\$5,\$6}' \` \"
export HISTSIZE=4096

DT=\`date \"+%Y-%m-%d\"\`
export DT

HISTORY_FILE=/var/log/cmd_history/\$DT-\${LOGNAME}.log

export PROMPT_COMMAND='history 1 | { read x cmd; echo \"\$cmd\"; } >>\$HISTORY_FILE'
" >> /etc/bashrc

yum -y install vim

systemctl disable firewalld.service

sed -i 's/SELINUX=enforcing/SELINUX=disable/' /etc/selinux/config

/usr/sbin/setenforce 0

if rpm -qa |grep xinetd
then
echo "xinetd is already installed"
else
yum -y install xinetd
fi

systemctl enable xinetd.service

systemctl start xinetd

if rpm -qa | grep telnet
then
echo "telnet is already installed"
else
yum -y install telnet
fi

if rpm -qa | grep telnet-server
then
echo "telnet-server is already installed"
else
yum -y install telnet-server
fi

echo "
pts/0
pts/1
pts/2
pts/3
pts/4
pts/5
pts/6
pts/7
pts/8
pts/9
pts/10
pts/11" >> /etc/securetty

systemctl enable telnet.socket

systemctl start telnet.socket

yum -y install httpd expect wget expat-devel openssl-devel sendmail sendmail-cf

useradd e1

useradd isys

./ssh_key_copy.sh

cd ~

mkdir -p installation_package

scp -r root@172.16.67.145:/root/installation_package/* /root/installation_package/

cd /root/installation_package

rpm -hiv oracle-instantclient11.2-basic-11.2.0.2.0.x86_64.rpm

rpm -hiv oracle-instantclient11.2-devel-11.2.0.2.0.x86_64.rpm

rpm -hiv oracle-instantclient11.2-sqlplus-11.2.0.2.0.x86_64.rpm

echo "export ORACLE_HOME=/usr/lib/oracle/11.2/client64
export C_INCLUDE_PATH=/usr/include/oracle/11.2/client64
export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client64/lib
" >> /etc/profile.d/oracle.sh

echo "/usr/lib/oracle/11.2/client64/lib
" >> /etc/ld.so.conf.d/oracle.conf

mkdir -p /usr/lib/oracle/11.2/client64/network/admin /usr/lib/oracle/11.2/client64/log/diag/clients

mkdir -p /opt/oracle

cd /opt/oracle

chown e1:isys .

mkdir -p bin product/10.1.0

cd product/10.1.0

ln -s /usr/lib/oracle/11.2/client64 client_1

scp -r root@172.16.67.145:/opt/oracle/bin/* /opt/oracle/bin/

scp -r root@172.16.67.145:/usr/lib/oracle/11.2/client64/network/admin/* /usr/lib/oracle/11.2/client64/network/admin/

useradd -c 'file forward gateway daemon' -d /opt/trs -g isys -s /bin/bash -u 501 forward

scp -r root@172.16.67.145:/opt/trs/bin /opt/trs/bin

scp -r root@172.16.67.145:/opt/trs/sbin /opt/trs/sbin

scp -r root@172.16.67.145:/opt/trs/etc /opt/trs/etc

scp -r root@172.16.67.145:/opt/trs/lib /opt/trs/lib

cd /opt/trs

chown -R forward:isys lib

sed -i "10262i trsd            9720/tcp                #trsd" /etc/services

echo "service trsd
{
disable = no
disable = no
socket_type = stream
wait = no
user = forward
server = /opt/trs/sbin/in.trsd
log_on_failure += USERID
}" >> /etc/xinetd.d/trs

mkdir -p /var/home

cd /var/home

mkdir cgi-bin docs

sed -i "s/root\tALL=(ALL) \tALL/root\tALL=(ALL) \tALL\ne1\t=ALL=(ALL) \tALL/" /etc/sudoers

cd /opt

mkdir isys e1

chown e1 e1

su - e1 <<EOF

mkdir -p ~/cent7/bin

cd ~/cent7/bin

wget --no-check-certificate http://xrl.us/cpanm

cd ~

curl -kL http://install.perlbrew.pl | bash

curl -O http://www.cpan.org/src/5.0/perl-5.16.3.tar.bz2

~/perl5/perlbrew/bin/perlbrew install perl-5.16.3 --as perl-5.16

~/perl5/perlbrew/bin/perlbrew switch perl-5.16

source ~/perl5/perlbrew/etc/bashrc

~/perl5/perlbrew/bin/perlbrew install_cpanm

tar zcf perl5.20170222.tgz perl5/

cpanm MLDBM
cpanm Jcode
cpanm HTML::Template
cpanm HTML::Tagset
cpanm HTML::Parser
cpanm URI
cpanm LWP
cpanm XML::RegExp
cpanm XML::Parser
cpanm XML::DOM
cpanm Net::SSLeay
cpanm IO::Socket::SSL
cpanm Crypt::SSLeay
cpanm IO::Tty
cpanm Expect
cpanm Term::ReadPassword
cpanm Net::SCP::Expect
cpanm Config::Simple
cpanm Crypt::DES
cpanm Crypt::DES_EDE3
cpanm Crypt::Blowfish
cpanm Crypt::Rijndael
cpanm Crypt::CBC
cpanm Data::Random
cpanm Class::MethodMaker
cpanm Date::Calc
cpanm XML::Simple
cpanm HTTP::DAV
cpanm Perl::Tidy
cpanm DBI
cpanm DBD::Oracle


EOF

scp root@172.16.67.145:/home/e1/perl5/perlbrew/perls/perl-5.16/lib/site_perl/5.16.3/x86_64-linux/XML/Parser/Encodings/euc-jp.enc /home/e1/perl5/perlbrew/perls/perl-5.16/lib/site_perl/5.16.3/x86_64-linux/XML/Parser/Encodings/

scp root@172.16.67.145:/home/e1/perl5/perlbrew/perls/perl-5.16/lib/site_perl/5.16.3/x86_64-linux/XML/Parser/Encodings/shift_jis.enc /home/e1/perl5/perlbrew/perls/perl-5.16/lib/site_perl/5.16.3/x86_64-linux/XML/Parser/Encodings/

chown e1:e1 /home/e1/perl5/perlbrew/perls/perl-5.16/lib/site_perl/5.16.3/x86_64-linux/XML/Parser/Encodings/euc-jp.enc /home/e1/perl5/perlbrew/perls/perl-5.16/lib/site_perl/5.16.3/x86_64-linux/XML/Parser/Encodings/shift_jis.enc

chmod 644 /home/e1/perl5/perlbrew/perls/perl-5.16/lib/site_perl/5.16.3/x86_64-linux/XML/Parser/Encodings/euc-jp.enc /home/e1/perl5/perlbrew/perls/perl-5.16/lib/site_perl/5.16.3/x86_64-linux/XML/Parser/Encodings/shift_jis.enc

cd /opt

ln -s ../usr free

cd /opt/isys

ln -s /home/e1/perl5/perlbrew/perls/perl-5.16/bin bin

scp -r root@172.16.67.145:/opt/customer /opt/

scp -r root@172.16.67.145:/opt/customer_bak /opt/

scp -r root@172.16.67.145:/opt/tools /opt/

sed -i "s/127.0.0.1 localhost/127.0.0.1 cdb.no1/" /etc/hosts

cd /opt/tools

./deploy_customer.sh E1_242_3045-dti_sim_contents_pack_ph3 >/tmp/deploy.log 2>&1

mkdir -p /var/trs/log /var/trs/spool

echo "">> /var/trs/log/trsd.log

echo "1">> /var/trs/spool/SEQ

chown -R forward:isys /var/trs

mkdir -p /var/log/customer

cd /var/log/customer

mkdir -p bin cdb cgi other stderr trs

chown -R e1:e1 /var/log/customer

chmod -R 777 /var/log/customer

chmod 755 /home/e1

systemctl restart xinetd

